[PHP] Kohana-v3 ORM parent relationship
Posted
by VDVLeon
on Stack Overflow
See other posts from Stack Overflow
or by VDVLeon
Published on 2010-05-23T14:11:29Z
Indexed on
2010/05/23
14:21 UTC
Read the original article
Hit count: 293
Hi all,
I just started with the version 3 of the Kohana Framework. I have worked a little with the $_has_many etc.
Now I have the table pages. The primary key is pageID. The table has a column called parentPageID. Now I want to make a ORM model who, when accesed like this $page->parent->find()
returns the page identified by parentPageID.
I have the following already:
// Settings
protected $_table_name = 'pages';
protected $_primary_key = 'pageID';
protected $_has_one = array(
'parent' => array(
'model' => 'page',
'foreign_key' => 'parentPageID',
),
);
But that does not work, it simply returns the first page from the table. Last query says this:
SELECT `pages`.* FROM `pages` ORDER BY `pages`.`pageID` ASC LIMIT 1
Does somebody know how to solve this?
I know this can: $parent = $page->parent->find($page->parentPageID);
but it must be and can be cleaner (I think).
© Stack Overflow or respective owner